﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.ObjectBuilder;
using Microsoft.Practices.CompositeWeb;

namespace ProjectDan.CRM.Views
{
    public class MaintainLinkPresenter : Presenter<IMaintainLinkView>
    {

        // NOTE: Uncomment the following code if you want ObjectBuilder to inject the module controller
        //       The code will not work in the Shell module, as a module controller is not created by default
        //
        private ICRMController _controller;
        public MaintainLinkPresenter([CreateNew] ICRMController controller)
        {
            _controller = controller;
        }

        public override void OnViewLoaded()
        {
            int id = View.ModelId;

            Common.LinkMaintainViewModel model = _controller.FindLinkMaintViewModelById(id);

            View.Show(model);
        }

        public override void OnViewInitialized()
        {
            // TODO: Implement code that will be executed the first time the view loads
        }

        // TODO: Handle other view events and set state in the view

        public void Update()
        {
            var id = View.ModelId;

            var model = _controller.FindLinkMaintViewModelById(id);

            View.UpdateModel(model);

            _controller.Save(model);
        }
    }
}




